package router

import (
	"github.com/xinliangnote/go-gin-api/internal/api/category"
	"github.com/xinliangnote/go-gin-api/internal/api/chain_config"
	"github.com/xinliangnote/go-gin-api/internal/api/config"
	"github.com/xinliangnote/go-gin-api/internal/api/operation_log"
	"github.com/xinliangnote/go-gin-api/internal/api/picture"
	"github.com/xinliangnote/go-gin-api/internal/api/product"
	"github.com/xinliangnote/go-gin-api/internal/api/token"
	"github.com/xinliangnote/go-gin-api/internal/api/up_coin"
	"github.com/xinliangnote/go-gin-api/internal/api/user"
	"github.com/xinliangnote/go-gin-api/internal/api/user_private_key"
	"github.com/xinliangnote/go-gin-api/internal/api/web_config"
	"github.com/xinliangnote/go-gin-api/internal/api/withdraw"
)

func setApiRouter(r *resource) {
	userHandler := user.New(r.logger, r.mongodb, r.cache)

	r.mux.Static("/upload", "./upload")
	configHandle := chain_config.New(r.logger, r.mongodb)
	configHandler := config.New(r.logger, r.db, r.cache)
	login := r.mux.Group("/user")
	{
		login.POST("/login", userHandler.Login())

		login.PATCH("/config/email", configHandler.Email())
	}

	webConfigHandle := web_config.New(r.logger, r.mongodb)
	applyTokenHandle := token.New(r.logger, r.mongodb)
	productHandler := product.New(r.logger, r.mongodb, r.cache)
	keyHandler := user_private_key.New(r.logger, r.mongodb, r.cache)
	pictureHandle := picture.New(r.logger, r.mongodb)
	categoryHandle := category.New(r.logger, r.mongodb, r.cache)

	upCoinHandle := up_coin.New(r.logger, r.mongodb)
	withdrawHandle := withdraw.New(r.logger, r.mongodb)
	logHandle := operation_log.New(r.logger, r.mongodb, r.cache)
	api := r.mux.Group("/api", r.interceptors.CheckSignature(r.mongodb.GetDb()))
	{
		api.POST("/createProduct", productHandler.Create())
		api.GET("/getProductList", productHandler.List())
		api.PATCH("/updateProduct", productHandler.Update())
		api.POST("/delete", productHandler.Delete())

		api.GET("/getApplyTokenList", applyTokenHandle.List())
		api.POST("/changePassword", userHandler.ChangePassword())
		api.POST("/createUser", userHandler.Create())
		api.POST("/updateUser", userHandler.Update())

		api.POST("/createPrivateKey", keyHandler.Create())
		api.GET("/getPrivateKeyList", keyHandler.List())
		api.PATCH("/updatePrivateKey", keyHandler.Update())
		api.DELETE("/deletePrivateKey/:id/:code", keyHandler.Delete())
		//更新手续费地址
		api.PATCH("/updateAddress", keyHandler.UpdateAddress())
		//更换密钥证书
		api.POST("/changePrivatePem", keyHandler.Change())

		api.GET("/getConfigList", configHandle.List())

		api.GET("/getUserList", userHandler.List())

		api.POST("/changeStatus", userHandler.ChangeStatus())

		//增加代币
		api.POST("/createToken", applyTokenHandle.CreateToken())
		api.GET("/tokenList", applyTokenHandle.TokenList())
		api.POST("/updateToken", applyTokenHandle.UpdateToken())
		api.POST("/deleteToken", applyTokenHandle.Delete())

		//网站信息管理
		api.POST("/createWebConfig", webConfigHandle.Create())
		api.GET("/getInfo", webConfigHandle.GetLatest())

		//轮播图管理
		api.POST("/createPicture", pictureHandle.Create())
		api.GET("/getPictureList", pictureHandle.List())
		api.PATCH("/updatePicture", pictureHandle.Update())
		api.DELETE("/deletePicture", pictureHandle.Delete())
		api.POST("/upload", pictureHandle.Upload())

		//类别管理
		api.POST("/createCategory", categoryHandle.Create())
		api.GET("/categoryList", categoryHandle.List())
		api.POST("/updateCategory", categoryHandle.Update())

		//充币列表
		api.GET("/upCoinList", upCoinHandle.List())
		//提币列表
		api.GET("/withdrawList", withdrawHandle.List())

		//操作日志列表
		api.GET("/operationLogList", logHandle.List())

	}

	// helper
	//helperHandler := helper.New(r.logger, r.db, r.cache)
	//
	//helpers := r.mux.Group("/helper")
	//{
	//	helpers.GET("/md5/:str", helperHandler.Md5())
	//	helpers.POST("/sign", helperHandler.Sign())
	//}
	//
	//// admin
	//adminHandler := admin.New(r.logger, r.db, r.cache)
	//
	//// 需要签名验证，无需登录验证，无需 RBAC 权限验证
	//login := r.mux.Group("/api", r.interceptors.CheckSignature())
	//{
	//	login.POST("/login", adminHandler.Login())
	//}
	//
	//// 需要签名验证、登录验证，无需 RBAC 权限验证
	//notRBAC := r.mux.Group("/api", core.WrapAuthHandler(r.interceptors.CheckLogin), r.interceptors.CheckSignature())
	//{
	//	notRBAC.POST("/admin/logout", adminHandler.Logout())
	//	notRBAC.PATCH("/admin/modify_password", adminHandler.ModifyPassword())
	//	notRBAC.GET("/admin/info", adminHandler.Detail())
	//	notRBAC.PATCH("/admin/modify_personal_info", adminHandler.ModifyPersonalInfo())
	//}
	//
	//// 需要签名验证、登录验证、RBAC 权限验证
	//api := r.mux.Group("/api", core.WrapAuthHandler(r.interceptors.CheckLogin), r.interceptors.CheckSignature(), r.interceptors.CheckRBAC())
	//{
	//	// authorized
	//	authorizedHandler := authorized.New(r.logger, r.db, r.cache)
	//	api.POST("/authorized", authorizedHandler.Create())
	//	api.GET("/authorized", authorizedHandler.List())
	//	api.PATCH("/authorized/used", authorizedHandler.UpdateUsed())
	//	api.DELETE("/authorized/:id", core.AliasForRecordMetrics("/api/authorized/info"), authorizedHandler.Delete())
	//
	//	api.POST("/authorized_api", authorizedHandler.CreateAPI())
	//	api.GET("/authorized_api", authorizedHandler.ListAPI())
	//	api.DELETE("/authorized_api/:id", core.AliasForRecordMetrics("/api/authorized_api/info"), authorizedHandler.DeleteAPI())
	//
	//	api.POST("/admin", adminHandler.Create())
	//	api.GET("/admin", adminHandler.List())
	//	api.PATCH("/admin/used", adminHandler.UpdateUsed())
	//	api.PATCH("/admin/offline", adminHandler.Offline())
	//	api.PATCH("/admin/reset_password/:id", core.AliasForRecordMetrics("/api/admin/reset_password"), adminHandler.ResetPassword())
	//	api.DELETE("/admin/:id", core.AliasForRecordMetrics("/api/admin"), adminHandler.Delete())
	//
	//	api.POST("/admin/menu", adminHandler.CreateAdminMenu())
	//	api.GET("/admin/menu/:id", core.AliasForRecordMetrics("/api/admin/menu"), adminHandler.ListAdminMenu())
	//
	//	// menu
	//	menuHandler := menu.New(r.logger, r.db, r.cache)
	//	api.POST("/menu", menuHandler.Create())
	//	api.GET("/menu", menuHandler.List())
	//	api.GET("/menu/:id", core.AliasForRecordMetrics("/api/menu"), menuHandler.Detail())
	//	api.PATCH("/menu/used", menuHandler.UpdateUsed())
	//	api.PATCH("/menu/sort", menuHandler.UpdateSort())
	//	api.DELETE("/menu/:id", core.AliasForRecordMetrics("/api/menu"), menuHandler.Delete())
	//	api.POST("/menu_action", menuHandler.CreateAction())
	//	api.GET("/menu_action", menuHandler.ListAction())
	//	api.DELETE("/menu_action/:id", core.AliasForRecordMetrics("/api/menu_action"), menuHandler.DeleteAction())
	//
	//	// tool
	//	toolHandler := tool.New(r.logger, r.db, r.cache)
	//	api.GET("/tool/hashids/encode/:id", core.AliasForRecordMetrics("/api/tool/hashids/encode"), toolHandler.HashIdsEncode())
	//	api.GET("/tool/hashids/decode/:id", core.AliasForRecordMetrics("/api/tool/hashids/decode"), toolHandler.HashIdsDecode())
	//	api.POST("/tool/cache/search", toolHandler.SearchCache())
	//	api.PATCH("/tool/cache/clear", toolHandler.ClearCache())
	//	api.GET("/tool/data/dbs", toolHandler.Dbs())
	//	api.POST("/tool/data/tables", toolHandler.Tables())
	//	api.POST("/tool/data/mysql", toolHandler.SearchMySQL())
	//	api.POST("/tool/send_message", toolHandler.SendMessage())
	//
	//	// config

	//
	//	// cron
	//	cronHandler := cron.New(r.logger, r.db, r.cache, r.cronServer)
	//	api.POST("/cron", cronHandler.Create())
	//	api.GET("/cron", cronHandler.List())
	//	api.GET("/cron/:id", core.AliasForRecordMetrics("/api/cron/detail"), cronHandler.Detail())
	//	api.POST("/cron/:id", core.AliasForRecordMetrics("/api/cron/modify"), cronHandler.Modify())
	//	api.PATCH("/cron/used", cronHandler.UpdateUsed())
	//	api.PATCH("/cron/exec/:id", core.AliasForRecordMetrics("/api/cron/exec"), cronHandler.Execute())
	//
	//}
}
